package com.lyandwc.lw_bbs.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lyandwc.lw_bbs.dao.CategoryDao;
import com.lyandwc.lw_bbs.entity.Category;
import com.lyandwc.lw_bbs.service.CategoryService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryDao, Category> implements CategoryService {
    @Override
    public List<Category> listCategories() {
        return this.baseMapper.listFatherCategories();
    }

    @Override
    public Category updateCount(int categoryId) {
        this.baseMapper.updateCategoryCountById(categoryId);
        return this.getById(categoryId);
    }

    @Override
    public void insertCategory(Category category, int fatherCategoryId) {
        if (fatherCategoryId >= 0) {
            category.setFatherCategoryId(fatherCategoryId);
        }
        this.save(category);
    }
}
